<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Closure;
use Cookie;

class Mt
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        session_start();
        if (isset($_SESSION['user'])) {
            $value = $_SESSION['user'];
            if(!$value) {
                echo json_encode(['code'=>10001,'msg'=>'未登录']);
                exit;
            }
            if(time()-$value['addtime'] >86400) {
                echo json_encode(['code'=>10001,'msg'=>'未登录']);
                exit;
            }
        } else {
            echo json_encode(['code'=>10001,'msg'=>'未登录']);
            exit;
        }
        return $next($request);
    }
    
}